package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜品表
 * @Author:zhq
 * @Date: 2025/08/15 22:02
 * @Description:
 */
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Long countByName(String name);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    Page<Dish> list(DishPageQueryDTO dishPageQueryDTO);

    Integer selectCountByIdsAndStatus(@Param("ids") List<Long> ids, @Param("status") Integer status);

    /**
     * 批量删除菜品
     * @param ids
     */
    void deleteByIds(@Param("ids") List<Long> ids);

    DishVO selectDishAndFlavorsById(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    List<Dish> selectByNameStatusCategoryId(Dish dish);

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> findBySetmealId(Long id);
}
